import AppReducer from '../reducers';
import  {NavigationReduxMiddleware} from "../../AppNavigator";
//import thunk from 'redux-thunk';
import createSagaMiddleware  from 'redux-saga';
import {createLogger} from 'redux-logger';
import {createStore,applyMiddleware} from 'redux';

import rootSaga from '../saga/saga';

//获取saga中间件

const middlewares = [];
const logger = createLogger({});
const saga   = createSagaMiddleware();
middlewares.push(NavigationReduxMiddleware);
//middlewares.push(thunk);
middlewares.push(saga);
middlewares.push(logger);
const store = createStore(AppReducer, applyMiddleware(...middlewares));
export default store;
saga.run(rootSaga);



// import AppReducer from "../reducers";
// import {middleware} from "../../AppNavigator";
// import { applyMiddleware, createStore } from 'redux';
// import thunk from 'redux-thunk';
// import { persistStore, autoRehydrate } from 'redux-persist';
// import { AsyncStorage } from 'react-native';
// import reducers from '../reducers';
//
// const logger = store => next => action => {
//     if(typeof action === 'function') console.log('dispatching a function');
//     else console.log('dispatching', action);
//     let result = next(action);
//     console.log('next state', store.getState());
//     return result;
// }
//
// let middlewares = [
//     logger,
//     thunk
// ];
//
// let createAppStore = applyMiddleware(...middlewares)(createStore);
//
//
// export default function configureStore(onComplete: ()=>void){
//     const store = autoRehydrate()(createAppStore)(reducers);
//     let opt = {
//         storage: AsyncStorage,
//         transform: [],
//         //whitelist: ['userStore'],
//     };
//     persistStore(store, opt, onComplete);
//     return store;
// }